﻿using DXApplicationTangche.UC.流程.Service;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.订单一览新.销售确认单
{
    public partial class Form条码查询 : DevExpress.XtraEditors.XtraForm
    {
        private CustomerTagQueryFacadeDTO customerTagQueryFacadeDTO = new CustomerTagQueryFacadeDTO();
        private ProcessInstanceRecordDTO processInstanceRecord;

        public Form条码查询()
        {
            InitializeComponent();
        }
        public Form条码查询(String saleOrderDetailId, String saleConfirmId)
        {
            InitializeComponent();
            this.customerTagQueryFacadeDTO = 销售确认Service.getCustomerTagRecordBySaleConfirmId(saleOrderDetailId, saleConfirmId);
            this.生产订单赋值();
            this.销售订单信息();
            this.相关销售订单();
        }

        private void textBox扫码_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (String.IsNullOrWhiteSpace(this.textBox扫码.Text))
                {
                    MessageBox.Show("条码为空");
                    return;
                }
                this.customerTagQueryFacadeDTO = 销售确认Service.getCustomerTagRecordByBarcode(this.textBox扫码.Text.Trim());
                this.processInstanceRecord = 流程Service.getBarcodeStatus(this.textBox扫码.Text.Trim());

                //判断是否可扫码发运
                if("成衣返修".Equals(this.processInstanceRecord.barcodeStatus)
                    || "套号下单".Equals(this.processInstanceRecord.barcodeStatus)
                    || "样品下单".Equals(this.processInstanceRecord.barcodeStatus)){
                    this.simpleButton查询发运信息.Enabled = false;
                    this.textBox扫码.Clear();
                    MessageBox.Show("样品、套号、成衣返修不可扫码发运！");
                    return;
                }
                else
                {
                    this.simpleButton查询发运信息.Enabled = true;
                    this.生产订单赋值();
                    this.销售订单信息();
                    this.相关销售订单();
                    this.其他客户订单();
                }
                this.textBox扫码.Clear();
            }
        }
        private void 生产订单赋值()
        {
            OrderCommitDTO返回 orderCommitDTO = this.customerTagQueryFacadeDTO.orderCommitDto;
            this.textBox订单号.Text = orderCommitDTO.orderNo;
            this.textBox款式.Text = orderCommitDTO.styleNameCn;
            this.textBox面料号.Text = orderCommitDTO.materialCode;
            this.textBox面料名称.Text = orderCommitDTO.materialNameCn;
            this.textBox成份.Text = orderCommitDTO.composition;
            if (!String.IsNullOrWhiteSpace(orderCommitDTO.styleSizeCd))
            {
                this.textBox尺码.Text = orderCommitDTO.styleSizeCd.Substring(15);
            }
            this.textBox参考成衣码.Text = orderCommitDTO.refBarcode;
            this.textBox订单数量.Text = orderCommitDTO.orderNumber.ToString();
            this.textBox订单时间.Text = orderCommitDTO.orderDate.ToString();
        }
        private void 销售订单信息()
        {
            CustomerTagRecordDTO customerTagRecordDTO = this.customerTagQueryFacadeDTO.barcodeRecords;
            this.textBox业务类型.Text = customerTagRecordDTO.businessType;
            this.textBox备注.Text = customerTagRecordDTO.remarks;
            this.textBox姓名.Text = customerTagRecordDTO.customerName;
            this.textBox电话.Text = customerTagRecordDTO.mobile;
            this.textBox数量.Text = customerTagRecordDTO.quantity.ToString();
            this.textBox门店.Text = customerTagRecordDTO.storeName;
            this.textBox销售员.Text = customerTagRecordDTO.assistantName;
            this.textBox成衣条码.Text = customerTagRecordDTO.barcode;
            this.textBox是否入库.Text = customerTagRecordDTO.stockIn.ToString().Equals("True")?"是":"否";
        }
        private void 相关销售订单()
        {
            List<CustomerTagRecordDTO> customerTagRecordDTOs = this.customerTagQueryFacadeDTO.relCustomerTagRecordDTOList;
            List<CustomerTagRecordDTO> customerTagRecordDTOs该客户其他订单 = new List<CustomerTagRecordDTO>();
            foreach (CustomerTagRecordDTO customerTagRecordDTO in customerTagRecordDTOs)
            {
                if (this.textBox电话.Text.Trim().Equals(customerTagRecordDTO.mobile))
                {
                    customerTagRecordDTOs该客户其他订单.Add(customerTagRecordDTO);
                }
            }
            this.gridControl订单信息.DataSource = customerTagRecordDTOs该客户其他订单;
            this.gridView订单信息.RefreshData();
            this.gridView订单信息.ExpandAllGroups();
        }
        private void 其他客户订单()
        {
            List<CustomerTagRecordDTO> customerTagRecordDTOs = this.customerTagQueryFacadeDTO.relCustomerTagRecordDTOList;
            List<CustomerTagRecordDTO> customerTagRecordDTOs其他客户订单 = new List<CustomerTagRecordDTO>();
            foreach (CustomerTagRecordDTO customerTagRecordDTO in customerTagRecordDTOs)
            {
                if (!this.textBox电话.Text.Trim().Equals(customerTagRecordDTO.mobile))
                {
                    customerTagRecordDTOs其他客户订单.Add(customerTagRecordDTO);
                }
            }
            this.gridControl其他客户销售订单.DataSource = customerTagRecordDTOs其他客户订单;
            this.gridView其他客户销售订单.RefreshData();
            this.gridView其他客户销售订单.ExpandAllGroups();
        }

        private void simpleButton查询发运信息_Click(object sender, EventArgs e)
        {
            new Form查询发运信息(this.textBox电话.Text.Trim(),this.textBox成衣条码.Text.Trim()).ShowDialog();
            this.ActiveControl = this.textBox扫码;
        }

        private void Form条码查询_Load(object sender, EventArgs e)
        {
            this.ActiveControl = this.textBox扫码;
        }
    }
}
